<template>
  <div class="wrapper">
    <FormPanel
      ref="formPanel"
      :list="inputs"
      labelWidth="150"
      :formType="type"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />


    <!-- table 是否全网下发-->
    <div v-show="disabled">
      <FilterTable
        height="300"
        ref="table"
        :columns="columnsxf"
        :dataSource="dataSource"
        :isSelectColumn="isSelectColumn"
        :params="flterValue"
        :isToperInfo="false"
        :datakey="'records'"
        :onColumnsChange="columnsxf => this.columnsxf = columnsxf"
        columnsRef="projectOperating_material_departmentService_info_01"
      >
        <template slot="controls">
          <el-button
            :disabled="type === 'show'"
            size="small"
            type="primary"
            icon="el-icon-plus"
            @click="dealerHandle"
          >添加经销商</el-button>
        </template>
      </FilterTable>
    </div>

    <!-- 是否全网下发选择经销商弹窗 -->
    <BaseDialog
      title="经销商查询"
      :visible.sync="visibleDealer"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <dealer-madal
        ref="addDialogRef"
        selectType="multiple"
        v-model="initDealerData"
        :deptId="orgId"
        :dealerType="dealerType"
        @close="closeDealer"
      />
    </BaseDialog>

    <!-- 经销商table -->
    <!-- <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      v-if="this.type == 'show'"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>-->

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
      <el-button
        :loading="zfLoading"
        v-if="this.type == 'edit'"
        type="primary"
        @click="zfDialog"
      >作 废</el-button>
      <el-button
        :loading="tyLoading"
        v-if="this.type == 'show' && this.materialStatus == '25361003'"
        type="primary"
        @click="tyDialog"
      >停 用</el-button>
      <el-button
        :loading="handLoading"
        v-if="this.type==='add' || this.type==='edit'"
        type="primary"
        @click="handDialog"
      >提 报</el-button>
      <el-button
        :loading="saveLoading"
        @click="saveDialog"
        v-if="this.type==='add' || this.type=='edit'"
        type="primary"
      >保 存</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import dealerMadal from '@/pages/cms-common/dealerdata/dealerTypeNew';
import {
  getDealers,
  getmaterialTypeOneList,
  getmaterialTypeName,
  saveMaterials,
  updateMaterial,
  getProjectMaterialDealer,
  selectMaterialListByBill
} from '@/api/cms-api/projectOperating/program/push';
// import { getLoginUser } from '@/api/cms-api/projectOperating/program/departmentInquire'; //获取登录信息
import { log } from 'util';
export default {
  mixins: [dictionary],
  components: { dealerMadal },
  props: {
    type: {
      type: String,
      required: true
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  mounted() {
    console.log(this.value);
  },
  data() {
    return {
      inputs: this.getInputs(),
      inputsData: {},
      formValue: {},
      dataParams: {}, //父类参数
      caseUrlList: [],
      // columns: this.creatHeader(),
      columnsxf: this.creatHeaderxf(),
      isSelectColumn: false,
      // fetchApi: getProjectMaterialDealer, //ipa 接口获取营销素材对应经销商信息
      // fetchParams: { materialId: this.rowData.materialId }, //参数
      saveLoading: false,
      handLoading: false,
      zfLoading: false,
      tyLoading: false,
      uploadPoint: [], //大附件上传name,url地址
      orgUrls: [],
      fileRoot: '', //大附件上传文件夹
      disabled: false, //是否可以添加经销商
      visibleDealer: false,
      orgId: null, //登录人所属组织
      dealerType: '25381001,25381002,25381004,25381005', //不包含大客户、单一售后的2020/1/11
      dataSource: [],
      initDealerData: {}, //经销商弹窗参数
      flterValue: {} //参数
    };
  },
  created() {
    this.init();
  },
  methods: {
    //搜索获取数据
    changeHandle(val) {
      this.flterValue = val;
    },
    // 经销商打开窗口 -传数据
    dealerHandle() {
      this.initDealerData = {
        excludeBigCustomer: false, //是否查询大客户经销商，如果查询 true，不查询 false
        id: 1001
      };
      this.visibleDealer = true;
    },
    // 经销商关闭窗口 -返回数据
    closeDealer(data) {
      // this.dataSource = data.data;
      this.addSelectDealer(data.data);
      this.visibleDealer = data.visible; //关闭弹窗
    },
    //添加选择经销商到列表中
    addSelectDealer(dealers) {
      if (dealers != null && typeof dealers != 'undefined' && dealers.length > 0)
        dealers.forEach(dealer => {
          let dealerCode = dealer.dealerCode;
          if (!this.isExistInDatasouce(dealerCode)) {
            let dealerNode = {
              deptName: '',
              dealerName: dealer.dealerName,
              ownerCode: dealer.dealerCode,
              dealerId: null,
              dealerShortname: dealer.dealerShortname,
              shopLevel: dealer.shopLevel,
              relationId: -1,
              managerId: 1,
              cityId: dealer.cityId,
              provinceId: dealer.provinceId,
              districtId: dealer.districtId,
              isDeleted: '0',
              majorManagerId: null,
              dealerType: 25031001
            };
            this.dataSource.push(dealerNode);
          }
        });
    },
    //判断经销商是否已经在列表中选择
    isExistInDatasouce(dealerCode) {
      let r = false;
      if (this.dataSource && this.dataSource.length > 0) {
        for (let dIdx = 0; dIdx < this.dataSource.length; dIdx++) {
          let tcode = this.dataSource[dIdx].ownerCode;
          if (tcode == dealerCode) {
            r = true;
            break;
          }
        }
      }
      return r;
    },
    //经销商列表删除
    editHandle(index) {
      this.$confirm('确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.dataSource.splice(index, 1);
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    //全网下发table表头和数据源
    creatHeaderxf() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: (props, h) => {
            if (this.type === 'show') {
              return (
                <div>
                  <el-button disabled size="mini" type="text" onClick={() => this.editHandle(props.$index)}>
                    删除
                  </el-button>
                </div>
              );
            } else {
              return (
                <div>
                  <el-button size="mini" type="text" onClick={() => this.editHandle(props.$index)}>
                    删除
                  </el-button>
                </div>
              );
            }
          }
        },
        { title: '公司全称', dataIndex: 'dealerName', sorter: true },
        { title: '经销商代码', dataIndex: 'ownerCode', sorter: true },
        { title: '经销商简称', dataIndex: 'dealerShortname', sorter: true }
      ];
    },
    //table表头和数据源
    // creatHeader() {
    //   return [
    //     {
    //       title: '序号',
    //       dataIndex: 'index',
    //       width: 80,
    //       sorter: true,
    //       render: props => {
    //         return <span>{props.row.index + 1}</span>;
    //       }
    //     },
    //     {
    //       title: '经销商代码',
    //       dataIndex: 'ownerCode',
    //       sorter: true
    //     },
    //     {
    //       title: '经销商简称',
    //       dataIndex: 'dealerName',
    //       sorter: true
    //     },
    //     {
    //       title: '是否查看',
    //       dataIndex: 'isView',
    //       sorter: true,
    //       filterItems: this.createDictList('1004'),
    //       render: props => {
    //         //编码转汉字
    //         return <span>{this.createDictText(props.row.isView, '1004')}</span>;
    //       }
    //     },
    //     {
    //       title: '首次查看人',
    //       dataIndex: 'firstViewPerson',
    //       sorter: true
    //     },
    //     {
    //       title: '首次查看时间',
    //       dataIndex: 'firstViewTime',
    //       sorter: true,
    //       render: props => {
    //         return <span>{this.formatDates(props.row.firstViewTime)} </span>;
    //       }
    //     }
    //   ];
    // },
    formatDates: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + '-' + month + '-' + day;
    },
    async init() {
      if (this.type === 'edit') {
        // 更新接口需要的记录 ID
        this.materialId = this.rowData.materialId;
        this.materialStatus = this.rowData.materialStatus;
        this.ownerCode = this.rowData.ownerCode;
        this.sourceDept = this.rowData.sourceDept;
        this.reviewPerson = this.rowData.reviewPerson;
        // console.log(this.rowData);
        //初始化二级
        this.initmaterialTypeTwo(this.rowData.materialTypeOne);
        //初始化三级
        this.initmaterialTypeThree(this.rowData.materialTypeTwo);
        //初始化四级
        if (this.rowData.materialTypeThree != null) {
          this.initmaterialTypeFour(this.rowData.materialTypeThree);
        }
        //初始化五级
        if (this.rowData.materialTypeFour != null) {
          this.initmaterialTypeFive(this.rowData.materialTypeFour);
        }

        //获取营销素材类型一、二、三、四、五级名称
        if (this.rowData.materialTypeOne != null) {
          this.getMaterialTypeOneName(this.rowData.materialTypeOne);
        }
        if (this.rowData.materialTypeTwo != null) {
          this.getMaterialTypeTwoName(this.rowData.materialTypeTwo);
        }
        if (this.rowData.materialTypeThree != null) {
          this.getMaterialTypeThreeName(this.rowData.materialTypeThree);
        }
        if (this.rowData.materialTypeFour != null) {
          this.getMaterialTypeFourName(this.rowData.materialTypeFour);
        }
        if (this.rowData.materialTypeFive != null) {
          this.getMaterialTypeFiveName(this.rowData.materialTypeFive);
        }
        //大附件
        let res = {};
        let fileParams = { materialId: this.materialId, billType: 25721003 };
        res = await selectMaterialListByBill(fileParams);
        if (res.data.length > 0) {
          let bigUrlList = [];
          for (let j = 0; j < res.data.length; j++) {
            let o1 = { name: res.data[j].fileName };
            let o2 = { url: res.data[j].fileId };
            let a = Object.assign(o1, o2);
            bigUrlList.push(a);
            this.orgUrls.push(res.data[j].fileId);
          }
          this.uploadPoint = bigUrlList;
        }
        //获取所选要下发的经销商
        if (this.rowData.isNetworkIssued == 10041002) {
          //非全网下发
          let resDealer = {};
          let dealerParams = { materialId: this.materialId };
          resDealer = await getDealers(dealerParams);
          console.log(resDealer);
          if (resDealer.resultCode == 200) {
            if (resDealer.data.length > 0) {
              let resDealerList = [];
              resDealer.data.forEach(x => {
                let dealer = {};
                dealer.dealerName = x.dealerName;
                dealer.ownerCode = x.dealerCode;
                dealer.dealerShortname = x.dealerShortname;
                resDealerList.push(dealer);
              });
              this.dataSource = resDealerList;
            }
          }
        }
        this.inputs.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
          if (x.fieldName == 'isNeedFeedback') {
            if (x.initialValue == 10041002) {
              //否
              this.inputs[10].disabled = true;
            } else {
              this.inputs[10].rules[0].required = true;
            }
          }
          if (x.fieldName == 'originalFileUrl') {
            x.initialValue = this.orgUrls;
          }
          if (x.fieldName == 'isNetworkIssued') {
            if (x.initialValue == 10041002) {
              this.disabled = true;
            }
          }
        });
      }
      if (this.type === 'show') {
        this.materialId = this.rowData.materialId;
        this.materialStatus = this.rowData.materialStatus;
        this.ownerCode = this.rowData.ownerCode;
        this.sourceDept = this.rowData.sourceDept;
        //初始化二级
        this.initmaterialTypeTwo(this.rowData.materialTypeOne);
        //初始化三级
        this.initmaterialTypeThree(this.rowData.materialTypeTwo);
        //初始化四级
        this.initmaterialTypeFour(this.rowData.materialTypeThree);
        //初始化五级
        this.initmaterialTypeFive(this.rowData.materialTypeFour);
        //大附件
        let res = {};
        let fileParams = { materialId: this.materialId, billType: 25721003 };
        res = await selectMaterialListByBill(fileParams);
        if (res.data.length > 0) {
          let bigUrlList = [];
          for (let j = 0; j < res.data.length; j++) {
            let o1 = { name: res.data[j].fileName };
            let o2 = { url: res.data[j].fileId };
            let a = Object.assign(o1, o2);
            bigUrlList.push(a);
            this.orgUrls.push(res.data[j].fileId);
          }
          this.uploadPoint = bigUrlList;
        }
        //获取所选要下发的经销商
        if (this.rowData.isNetworkIssued == 10041002) {
          //非全网下发
          let resDealer = {};
          let dealerParams = { materialId: this.materialId };
          resDealer = await getDealers(dealerParams);
          console.log(resDealer);
          if (resDealer.resultCode == 200) {
            if (resDealer.data.length > 0) {
              let resDealerList = [];
              resDealer.data.forEach(x => {
                let dealer = {};
                dealer.dealerName = x.dealerName;
                dealer.ownerCode = x.dealerCode;
                dealer.dealerShortname = x.dealerShortname;
                resDealerList.push(dealer);
              });
              this.dataSource = resDealerList;
            }
          }
        }
        this.inputs.forEach(x => {
          x.initialValue = this.rowData[x.fieldName];
          if (x.fieldName == 'originalFileUrl') {
            x.initialValue = this.orgUrls;
          }
          if (x.fieldName == 'isNetworkIssued') {
            if (x.initialValue == 10041002) {
              this.disabled = true;
            }
          }
        });
      }
    },
    formChangeHandle(val) {
      this.formValue = val;
    },
    getInputs() {
      return [
        {
          type: 'INPUT',
          label: '营销素材代码',
          disabled: true,
          fieldName: 'materialCode',
          placeholder: '系统自动生成',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '营销素材名称',
          fieldName: 'materialName',
          placeholder: '请输入...',
          initialValue: '',
          rules: [{ required: true, message: '请输入营销素材名称', trigger: 'blur' }, { max: 20, message: '名称长度不能超过20', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '来源部门',
          disabled: true,
          fieldName: 'orgName',
          placeholder: '',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '营销素材类型-一级',
          fieldName: 'materialTypeOne',
          placeholder: '请选择...',
          //           request:{
          //                   fetchApi:getmaterialTypeOneList,
          //                   params:{},
          //                   valueKey:'materialTypeId',
          //                   textKey:'materialTypeName'},
          itemList: [],
          change: value => {
            this.initmaterialTypeTwo(value);
            this.getMaterialTypeOneName(value);
          },
          rules: [{ required: true, message: '请选择营销素材类型-一级', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '营销素材类型-二级',
          fieldName: 'materialTypeTwo',
          placeholder: '请选择...',
          itemList: [],
          change: value => {
            this.initmaterialTypeThree(value);
            this.getMaterialTypeTwoName(value);
          },
          rules: [{ required: true, message: '请选择营销素材类型-二级', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '营销素材类型-三级',
          fieldName: 'materialTypeThree',
          placeholder: '请选择...',
          itemList: [],
          change: value => {
            this.initmaterialTypeFour(value);
            this.getMaterialTypeThreeName(value);
          }
        },
        {
          type: 'SELECT',
          label: '营销素材类型-四级',
          fieldName: 'materialTypeFour',
          placeholder: '请选择...',
          itemList: [],
          change: value => {
            this.initmaterialTypeFive(value);
            this.getMaterialTypeFourName(value);
          }
        },
        {
          type: 'SELECT',
          label: '营销素材类型-五级',
          fieldName: 'materialTypeFive',
          placeholder: '请选择...',
          itemList: [],
          change: value => {
            this.getMaterialTypeFiveName(value);
          }
        },
        {
          type: 'INPUT',
          label: '使用场景',
          fieldName: 'usedScenes',
          placeholder: '请输入...',
          initialValue: '',
          selfCols: 3,
          rules: [{ max: 300, message: '使用场景长度不能超过300', trigger: 'blur' }]
        },
        // {
        //   type: 'SELECT',
        //   label: '营销素材状态',
        //   disabled: true,
        //   fieldName: 'materialStatus',
        //   placeholder: '请选择...',
        //   initialValue: '25361001',
        //   itemList: this.createDictList('2536')
        // },
        {
          type: 'SELECT',
          label: '是否需要反馈',
          fieldName: 'isNeedFeedback',
          placeholder: '请选择...',
          itemList: this.createDictList('1004'),
          change: this.isAllChange,
          rules: [{ required: true, message: '请选择是否需要反馈', trigger: 'change' }]
        },
        {
          type: 'DATE',
          label: '反馈截止日期',
          fieldName: 'feedbackEndDate',
          placeholder: '请选择...',
          initialValue: '',
          disabled: false,
          valueFormat: 'yyyy-MM-dd',
          rules: [{ required: false, message: '请输入反馈截止日期', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '是否全网下发',
          fieldName: 'isNetworkIssued',
          placeholder: '请选择...',
          itemList: this.createDictList('1004'),
          change: this.isChanged,
          rules: [{ required: true, message: '请选择是否全网下发', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '审核人',
          fieldName: 'reviewPersonName',
          placeholder: '',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '审核意见',
          fieldName: 'reviewIdea',
          placeholder: '',
          initialValue: '',
          selfCols: 3,
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '原始文件下载地址',
          fieldName: 'originalFileUrl',
          placeholder: '',
          initialValue: '',
          selfCols: 3,
          // disabled: true
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件缩略图',
          fieldName: 'caseUrl',
          selfCols: 3,
          // rules: [{ limit: 1, validator: this.validateFn, message: '最多上传1张', trigger: 'change' }],
          upload: {
            actionUrl: '/api/file/oss/upload',
            fileTypes: ['jpg', 'png']
          }
        }
      ];
    },
    // getUrl(val) {
    //   if (this.uploadPoint.length == 0) {
    //     this.uploadPoint.push(val);
    //   } else {
    //     this.$notify.warning({ title: '提示信息', message: '原始文件仅限上传一个!' });
    //     return;
    //   }
    // },
    isChanged(val) {
      if (val === 10041001) {
        this.disabled = false;
      } else {
        this.disabled = true;
      }
    },
    async getMaterialTypeOneName(value) {
      let dataParams = { materialTypeId: value };
      let rd = await getmaterialTypeName(dataParams);
      for (let i in rd.data) {
        this.fileRoot = rd.data[i].materialTypeName;
      }
    },
    async getMaterialTypeTwoName(value) {
      let dataParams = { materialTypeId: value };
      let rd = await getmaterialTypeName(dataParams);
      for (let i in rd.data) {
        this.fileRoot += '/' + rd.data[i].materialTypeName + '/';
      }
    },
    async getMaterialTypeThreeName(value) {
      let dataParams = { materialTypeId: value };
      let rd = await getmaterialTypeName(dataParams);
      for (let i in rd.data) {
        this.fileRoot += rd.data[i].materialTypeName + '/';
      }
    },
    async getMaterialTypeFourName(value) {
      let dataParams = { materialTypeId: value };
      let rd = await getmaterialTypeName(dataParams);
      for (let i in rd.data) {
        this.fileRoot += rd.data[i].materialTypeName + '/';
      }
    },
    async getMaterialTypeFiveName(value) {
      let dataParams = { materialTypeId: value };
      let rd = await getmaterialTypeName(dataParams);
      for (let i in rd.data) {
        this.fileRoot += rd.data[i].materialTypeName + '/';
      }
    },
    //取营销素材类型-一级
    async initmaterialTypeOne() {
      let res = [];
      this.dataParams = { parentTypeId: '' };
      let rd = await getmaterialTypeOneList(this.dataParams);
      for (let i in rd.data) {
        res.push({ text: rd.data[i].materialTypeName, value: rd.data[i].materialTypeId });
      }
      this.inputs[3].itemList = res;
    },
    //取营销素材类型-二级
    async initmaterialTypeTwo(parentTypeId) {
      this.inputs.find(item => item.fieldName === 'materialTypeTwo').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeThree').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFour').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFive').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeTwo').itemList = [];
      this.inputs.find(item => item.fieldName === 'materialTypeThree').itemList = [];
      this.inputs.find(item => item.fieldName === 'materialTypeFour').itemList = [];
      this.inputs.find(item => item.fieldName === 'materialTypeFive').itemList = [];
      if (parentTypeId != '') {
        let res = [];
        this.dataParams = { parentTypeId: parentTypeId };
        let rd = await getmaterialTypeOneList(this.dataParams);
        for (let i in rd.data) {
          res.push({ text: rd.data[i].materialTypeName, value: rd.data[i].materialTypeId });
        }
        this.inputs[4].itemList = res;
      }
    },
    //取营销素材类型-三级
    async initmaterialTypeThree(parentTypeId) {
      this.inputs.find(item => item.fieldName === 'materialTypeThree').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFour').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFive').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeThree').itemList = [];
      this.inputs.find(item => item.fieldName === 'materialTypeFour').itemList = [];
      this.inputs.find(item => item.fieldName === 'materialTypeFive').itemList = [];
      if (parentTypeId != '') {
        let res = [];
        this.dataParams = { parentTypeId: parentTypeId };
        let rd = await getmaterialTypeOneList(this.dataParams);
        for (let i in rd.data) {
          res.push({ text: rd.data[i].materialTypeName, value: rd.data[i].materialTypeId });
        }
        this.inputs[5].itemList = res;
      }
    },
    //取营销素材类型-四级
    async initmaterialTypeFour(parentTypeId) {
      this.inputs.find(item => item.fieldName === 'materialTypeFour').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFive').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFour').itemList = [];
      this.inputs.find(item => item.fieldName === 'materialTypeFive').itemList = [];
      if (parentTypeId != '') {
        let res = [];
        this.dataParams = { parentTypeId: parentTypeId };
        let rd = await getmaterialTypeOneList(this.dataParams);
        for (let i in rd.data) {
          res.push({ text: rd.data[i].materialTypeName, value: rd.data[i].materialTypeId });
        }
        this.inputs[6].itemList = res;
      }
    },
    //取营销素材类型-五级
    async initmaterialTypeFive(parentTypeId) {
      this.inputs.find(item => item.fieldName === 'materialTypeFive').initialValue = '';
      this.inputs.find(item => item.fieldName === 'materialTypeFive').itemList = [];
      if (parentTypeId != '') {
        let res = [];
        this.dataParams = { parentTypeId: parentTypeId };
        let rd = await getmaterialTypeOneList(this.dataParams);
        for (let i in rd.data) {
          res.push({ text: rd.data[i].materialTypeName, value: rd.data[i].materialTypeId });
        }
        this.inputs[7].itemList = res;
      }
    },
    checkedEnclosure() {
      //选择附件
    },
    changeHandle(data) {
      this.inputsData = data;
      this.$emit('close', data);
    },
    //是否需要反馈
    isAllChange(val) {
      if (val === 10041001) {
        // this.inputs[10].disabled = false;
        this.inputs[10].rules[0].required = true;
        this.inputs[10].disabled = false;
      } else {
        // this.inputs[10].disabled = true;
        this.inputs[10].rules[0].required = false;
        this.inputs[10].disabled = true;
        this.$refs.formPanel.$refs.form.clearValidate();
      }
    },
    //保存
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (null == this.$refs.formPanel.SUBMIT_FORM()) {
        return;
      }
      if (this.formValue !== null) {
        let dealerList = [];
        this.dataSource.forEach(x => {
          let dealer = {};
          dealer.dealerId = x.dealerId;
          dealer.dealerName = x.dealerName;
          dealer.ownerCode = x.ownerCode;
          dealerList.push(dealer);
        });
        this.formValue = Object.assign({}, { dealerList: dealerList }, this.formValue);
        if (this.formValue.isNetworkIssued == 10041002) {
          //是全网下发，判断是否添加了经销商
          if (this.formValue.dealerList.length == 0) {
            this.$notify.warning({ title: '提示信息', message: '请选择添加要下发的经销商!' });
            return false;
          }
        }
        this.saveLoading = true;
        let result = {};
        if (this.type === 'add') {
          //追加隐藏状态字段
          this.formValue = Object.assign({}, { materialStatus: 25361001 }, this.formValue);
          if (this.formValue.caseUrl != null) {
            for (let i = 0; i < this.formValue.caseUrl.length; i++) {
              this.caseUrlList.push(Object.assign({}, { name: this.formValue.caseUrl[i].name }, { url: this.formValue.caseUrl[i].url }));
            }
            this.formValue = Object.assign({}, { fileUrl: this.caseUrlList }, this.formValue);
          }
          // console.log(this.uploadPoint);
          //大附件上传
          if (this.uploadPoint.length > 0) {
            this.formValue = Object.assign({}, { bigFileUrl: this.uploadPoint }, this.formValue);
          }
          // console.log(this.formValue);
          result = await saveMaterials(this.formValue);
          if (result.resultCode === 200) {
            this.saveLoading = false;
            this.$notify.success({ title: '提示信息', message: '新增成功!' });
            this.closeDialog('refresh');
          }
        }
        if (this.type === 'edit') {
          if (this.formValue.caseUrl != null) {
            for (let i = 0; i < this.formValue.caseUrl.length; i++) {
              this.caseUrlList.push(Object.assign({}, { name: this.formValue.caseUrl[i].name }, { url: this.formValue.caseUrl[i].url }));
            }
            this.formValue = Object.assign({}, { fileUrl: this.caseUrlList }, this.formValue);
          }
          //大附件上传
          if (this.uploadPoint.length > 0) {
            this.formValue = Object.assign({}, { bigFileUrl: this.uploadPoint }, this.formValue);
          }
          this.formValue = Object.assign({}, { materialStatus: this.materialStatus }, this.formValue);
          this.formValue = Object.assign({}, { ownerCode: this.ownerCode }, this.formValue);
          //来源部门
          this.formValue = Object.assign({}, { sourceDept: this.sourceDept }, this.formValue);
          //审核人
          this.formValue = Object.assign({}, { reviewPerson: this.reviewPerson }, this.formValue);
          //大附件地址替换为空
          this.formValue = Object.assign({}, this.formValue, { originalFileUrl: '' });
          result = await updateMaterial(this.formValue, this.materialId);
          if (result.resultCode === 200) {
            this.saveLoading = false;
            this.$notify.success({ title: '提示信息', message: '编辑成功!' });
            this.closeDialog('refresh');
          }
        }
      }
    },
    //提报
    async handDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (null == this.$refs.formPanel.SUBMIT_FORM()) {
        return;
      }
      if (this.formValue !== null) {
        let dealerList = [];
        this.dataSource.forEach(x => {
          let dealer = {};
          dealer.dealerId = x.dealerId;
          dealer.dealerName = x.dealerName;
          dealer.ownerCode = x.ownerCode;
          dealerList.push(dealer);
        });
        this.formValue = Object.assign({}, { dealerList: dealerList }, this.formValue);
        if (this.formValue.isNetworkIssued == 10041002) {
          //是全网下发，判断是否添加了经销商
          if (this.formValue.dealerList.length == 0) {
            this.$notify.warning({ title: '提示信息', message: '请选择添加要下发的经销商!' });
            return false;
          }
        }
        this.handLoading = true;
        let result = {};
        if (this.type === 'add') {
          //追加隐藏状态字段
          this.formValue = Object.assign({}, { materialStatus: 25361002 }, this.formValue);
          if (this.formValue.caseUrl != null) {
            for (let i = 0; i < this.formValue.caseUrl.length; i++) {
              this.caseUrlList.push(Object.assign({}, { name: this.formValue.caseUrl[i].name }, { url: this.formValue.caseUrl[i].url }));
            }
            this.formValue = Object.assign({}, { fileUrl: this.caseUrlList }, this.formValue);
          }
          //大附件上传
          if (this.uploadPoint.length > 0) {
            this.formValue = Object.assign({}, { bigFileUrl: this.uploadPoint }, this.formValue);
          }
          // console.log(this.formValue);
          // result = await updateMaterial(this.formValue, this.materialId);
          result = await saveMaterials(this.formValue);
          if (result.resultCode === 200) {
            this.handLoading = false;
            this.$notify.success({ title: '提示信息', message: '提报成功!' });
            this.closeDialog('refresh');
          }
        }
        if (this.type === 'edit') {
          //追加隐藏状态字段
          this.formValue = Object.assign({}, { materialStatus: 25361002 }, this.formValue);
          if (this.formValue.caseUrl != null) {
            for (let i = 0; i < this.formValue.caseUrl.length; i++) {
              this.caseUrlList.push(Object.assign({}, { name: this.formValue.caseUrl[i].name }, { url: this.formValue.caseUrl[i].url }));
            }
            this.formValue = Object.assign({}, { fileUrl: this.caseUrlList }, this.formValue);
          }
          //大附件上传
          if (this.uploadPoint.length > 0) {
            this.formValue = Object.assign({}, { bigFileUrl: this.uploadPoint }, this.formValue);
          }
          this.formValue = Object.assign({}, { ownerCode: this.ownerCode }, this.formValue);
          //来源部门
          this.formValue = Object.assign({}, { sourceDept: this.sourceDept }, this.formValue);
          //审核人
          this.formValue = Object.assign({}, { reviewPerson: this.reviewPerson }, this.formValue);
          //大附件地址替换为空
          this.formValue = Object.assign({}, this.formValue, { originalFileUrl: '' });
          // console.log(this.formValue);
          result = await updateMaterial(this.formValue, this.materialId);
          if (result.resultCode === 200) {
            this.handLoading = false;
            this.$notify.success({ title: '提示信息', message: '提报成功!' });
            this.closeDialog('refresh');
          }
        }
      }
    },
    //作废
    async zfDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (null == this.$refs.formPanel.SUBMIT_FORM()) {
        return;
      }
      if (this.formValue !== null) {
        let dealerList = [];
        this.dataSource.forEach(x => {
          let dealer = {};
          dealer.dealerId = x.dealerId;
          dealer.dealerName = x.dealerName;
          dealer.ownerCode = x.ownerCode;
          dealerList.push(dealer);
        });
        this.formValue = Object.assign({}, { dealerList: dealerList }, this.formValue);
        this.zfLoading = true;
        //追加隐藏状态字段
        this.formValue = Object.assign({}, { materialStatus: 25361006 }, this.formValue);
        let result = {};
        if (this.type === 'edit') {
          if (this.formValue.caseUrl != null) {
            for (let i = 0; i < this.formValue.caseUrl.length; i++) {
              this.caseUrlList.push(Object.assign({}, { name: this.formValue.caseUrl[i].name }, { url: this.formValue.caseUrl[i].url }));
            }
            this.formValue = Object.assign({}, { fileUrl: this.caseUrlList }, this.formValue);
          }
          //来源部门
          this.formValue = Object.assign({}, { sourceDept: this.sourceDept }, this.formValue);
          //审核人
          this.formValue = Object.assign({}, { reviewPerson: this.reviewPerson }, this.formValue);
          //大附件地址替换为空
          this.formValue = Object.assign({}, this.formValue, { originalFileUrl: '' });
          result = await updateMaterial(this.formValue, this.materialId);
          if (result.resultCode === 200) {
            this.zfLoading = false;
            this.$notify.success({ title: '提示信息', message: '已作废!' });
            this.closeDialog('refresh');
          }
        }
      }
    },
    //停用
    async tyDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (null == this.$refs.formPanel.SUBMIT_FORM()) {
        return;
      }
      if (this.formValue !== null) {
        let dealerList = [];
        this.dataSource.forEach(x => {
          let dealer = {};
          dealer.dealerId = x.dealerId;
          dealer.dealerName = x.dealerName;
          dealer.ownerCode = x.ownerCode;
          dealerList.push(dealer);
        });
        this.formValue = Object.assign({}, { dealerList: dealerList }, this.formValue);
        this.tyLoading = true;
        //追加隐藏状态字段
        this.formValue = Object.assign({}, { materialStatus: 25361005 }, this.formValue);
        let result = {};
        if (this.type === 'show') {
          if (this.formValue.caseUrl != null) {
            for (let i = 0; i < this.formValue.caseUrl.length; i++) {
              this.caseUrlList.push(Object.assign({}, { name: this.formValue.caseUrl[i].name }, { url: this.formValue.caseUrl[i].url }));
            }
            this.formValue = Object.assign({}, { fileUrl: this.caseUrlList }, this.formValue);
          }
          this.formValue = Object.assign({}, { ownerCode: this.ownerCode }, this.formValue);
          this.formValue = Object.assign({}, { sourceDept: this.sourceDept }, this.formValue);
          //审核人
          this.formValue = Object.assign({}, { reviewPerson: this.reviewPerson }, this.formValue);
          //大附件地址替换为空
          this.formValue = Object.assign({}, this.formValue, { originalFileUrl: '' });
          result = await updateMaterial(this.formValue, this.materialId);
          if (result.resultCode === 200) {
            this.tyLoading = false;
            this.$notify.success({ title: '提示信息', message: '已停用!' });
            this.closeDialog('refresh');
          }
        }
      }
    },
    //取消操作
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    async getUserInfo() {
      this.loginUser = await getLoginUser({});
      if (this.loginUser.resultCode == 200) {
        this.inputs[2].initialValue = this.loginUser.data.orgName;
        if (this.loginUser.data.orgType == 15061005) {
          //是事业部
          this.orgId = this.loginUser.data.orgId;
        }
      }
    }
  },
  mounted() {
    //初始化营销素材类型-一级
    this.initmaterialTypeOne();
    //初始化登录人来源部门
    // this.getUserInfo();
  }
};
</script>
<style scoped>
.wrapper {
  height: calc(100vh - 110px);
}
</style>
